from django.shortcuts import render
from django.views.generic.base import View
import json


class ChartsView(View):
    def get(self, request):
        # 准备要显示的数据
        showdata = []
        showdata.append({'key': {'name': "\u5355\u63d2\u914d\u4ef6", 'val': ["null", "null", 4, 4, 4], 'color': colorful(1)}})
        try:
            mylist = showdata
            return render(request, 'chart/charts.html', {'equitments': json.dumps(mylist)})
        except Exception as e:
            print(e)
        return render(request, 'chart/charts.html')


def colorful(i):
    temp = i % 10
    colordict = {'0': 'blue', '1': 'red', '2': 'blue', '3': '#FF1493', '4': '#8E8E8E', '5': '#080808', '6': '#836FFF', '7': '#B03060', '8': '#B0E2FF', '9': '#7A378B'}
    return colordict[str(temp)]

